<?php
/**
 *+------------------
 * Lflow
 *+------------------
 * Copyright (c) 2023~2030 gitee.com/liu_guan_qing All rights reserved.本版权不可删除，侵权必究
 *+------------------
 * Author: Mr.April(405784684@qq.com)
 *+------------------
 */
declare (strict_types=1);

namespace lflow\entity;

class HistoryTask
{
    /**
     * 主键ID
     */
    private string $id;
    /**
     * 流程实例ID
     */
    private string $order_id;
    /**
     * 任务名称
     */
    private string $task_name;
    /**
     * 任务显示名称
     */
    private string $display_name;
    /**
     * 参与方式（0：普通任务；1：参与者fork任务[即：如果10个参与者，需要每个人都要完成，才继续流转]）
     */
    private int $perform_type;
    /**
     * 任务类型
     */
    private int $task_type;
    /**
     * 任务状态（0：结束；1：活动）
     */
    private int $task_state;
    /**
     * 任务处理者ID
     */
    private string $operator;
    /**
     * 任务创建时间
     */
    private string $create_time;
    /**
     * 任务完成时间
     */
    private string $finish_time;
    /**
     * 期望任务完成时间
     */
    private string $expire_time;
    /**
     * 任务关联的表单url
     */
    private string $action_url;
    /**
     * 任务参与者列表
     */
    private array $actor_ids;
    /**
     * 父任务Id
     */
    private string $parent_task_id;
    /**
     * 任务附属变量
     */
    private string $variable;

    public function getParentTaskId(): string
    {
        return $this->parent_task_id;
    }

    public function setParentTaskId(string $parentTaskId)
    {
        $this->parent_task_id = $parentTaskId;
    }

    public function getVariable(): string
    {
        return $this->variable;
    }

    public function setVariable(string $variable)
    {
        $this->variable = $variable;
    }

    public function historyTask(Task $task)
    {
        $this->id             = $task->getId();
        $this->order_id       = $task->getOrderId();
        $this->create_time    = $task->getCreateTime();
        $this->display_name   = $task->getDisplayName();
        $this->task_name      = $task->getTaskName();
        $this->task_type      = $task->getTaskType();
        $this->expire_time    = $task->getExpireTime();
        $this->action_url     = $task->getActionUrl();
        $this->actor_ids      = $task->getActorIds();
        $this->parent_task_id = $task->getParentTaskId();
        $this->variable       = $task->getVariable();
        $this->perform_type   = $task->getPerformType();
    }

    /**
     * 根据历史任务产生撤回的任务对象
     *
     * @return \lflow\entity\Task
     */
    public function undoTask(): Task
    {
        $task = new Task();
        $task->setOrderId($this->getOrderId());;
        $task->setTaskName($this->getTaskName());
        $task->setDisplayName($this->getDisplayName());
        $task->setTaskType($this->getTaskType());
        $task->setExpireTime($this->getExpireTime());
        $task->setActionUrl($this->getActionUrl());
        $task->setParentTaskId($this->getParentTaskId());
        $task->setVariable($this->getVariable());
        $task->setPerformType($this->getPerformType());
        $task->setOperator($this->getOperator());
        return $task;
    }

    public function isPerformAny(): bool
    {
        return false;
    }

    public function getTaskName(): string
    {
        return $this->task_name;
    }

    public function setTaskName(string $taskName): void
    {
        $this->task_name = $taskName;
    }

    public function getTaskType(): int
    {
        return $this->task_type;
    }

    public function setTaskType(int $taskType): void
    {
        $this->task_type = $taskType;
    }

    public function getTaskState(): int
    {
        return $this->task_state;
    }

    public function setTaskState(int $taskState): void
    {
        $this->task_state = $taskState;
    }

    public function getOperator(): string
    {
        return $this->operator;
    }

    public function setOperator(string $operator)
    {
        $this->operator = $operator;
    }

    public function getCreateTime(): string
    {
        return $this->create_time;
    }

    public function setCreateTime(string $createTime): void
    {
        $this->create_time = $createTime;
    }

    public function getFinishTime(): string
    {
        return $this->finish_time;
    }

    public function setFinishTime(string $finishTime): void
    {
        $this->finish_time = $finishTime;
    }

    public function getExpireTime(): string
    {
        return $this->expire_time;
    }

    public function setExpireTime(string $expireTime)
    {
        $this->expire_time = $expireTime;
    }

    public function getActionUrl(): string
    {
        return $this->action_url;
    }

    public function setActionUrl(string $actionUrl): void
    {
        $this->action_url = $actionUrl;
    }

    public function getDisplayName(): string
    {
        return $this->display_name;
    }

    public function setDisplayName(string $displayName): void
    {
        $this->display_name = $displayName;
    }

    public function getId(): string
    {
        return $this->id;
    }

    public function setId(string $id)
    {
        $this->id = $id;
    }

    public function getOrderId(): string
    {
        return $this->order_id;
    }

    public function setOrderId(string $orderId): void
    {
        $this->order_id = $orderId;
    }

    public function getPerformType(): int
    {
        return $this->perform_type;
    }

    public function setPerformType(int $performType): void
    {
        $this->perform_type = $performType;
    }

    public function getActorIds(): array
    {
        return $this->actor_ids;
    }

    public function setActorIds(array $actorIds): void
    {
        $this->actor_ids = $actorIds;
    }

    public function getVariableMap(): object
    {
        return isset($this->variable) && empty($this->variable) ? json_decode($this->variable) : (object)[];
    }

    public function toString(): string
    {
        return json_encode(get_object_vars($this));

    }

    public function toArray(): array
    {
        return get_object_vars($this);
    }

}